# -*- coding: utf-8 -*-
"""
Created on Wed Apr 22 11:57:04 2020

@author: Administrator
"""

import os
import pickle
import time

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
'''
brower = webdriver.Chrome('C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chromedriver.exe')
wait = WebDriverWait(brower, 10)

def getTaobaoCookies():
    # get login taobao cookies
    url = "http://srm.lbxdrugs.com:6066/srm/skins/default/index.jsp"
    brower.get("http://srm.lbxdrugs.com:6066/srm/coframe/auth/login/login.jsp")
    while True:
        print("Please login in taobao.com!")
        time.sleep(3)
        # if login in successfully, url  jump to www.taobao.com
        while brower.current_url ==  url:
            tbCookies  = brower.get_cookies()
            brower.quit()
            cookies = {}
            for item in tbCookies:
                cookies[item['name']] = item['value']
            outputPath = open('taobaoCookies.pickle','wb')
            pickle.dump(cookies,outputPath)
            outputPath.close()
            return cookies
def readTaobaoCookies():
    # if hava cookies file ,use it 
    # if not , getTaobaoCookies()
    if os.path.exists('taobaoCookies.pickle'):
        readPath = open('taobaoCookies.pickle','rb')
        tbCookies = pickle.load(readPath)
    else:
        tbCookies = getTaobaoCookies()
    return tbCookies
tbCookies = readTaobaoCookies()

getTaobaoCookies()

brower.get("http://srm.lbxdrugs.com:6066/srm/skins/default/index.jsp")
for cookie in tbCookies:
    brower.add_cookie({
        "domain":".taobao.com",
        "name":cookie,
        "value":tbCookies[cookie],
        "path":'/',
        "expires":None
    })
brower.get("http://srm.lbxdrugs.com:6066/srm/skins/default/index.jsp")
'''


browser = webdriver.Chrome('C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chromedriver.exe')
browser.maximize_window()   #设置浏览器大小：全屏
browser.get(' http://vendor.yfdyf.cn/sup/login')  
def input_a(id_1,value):
    input_box = browser.find_element_by_id(id_1)
    try:
        #输入内容：selenium
        input_box.send_keys(value)
        print('输入成功')
    except Exception as e:
        print('fail')
def input_b(id_1,value):
    input_box = browser.find_element_by_xpath(id_1)
    try:
        #输入内容：selenium
        input_box.send_keys(value)
        print('输入成功')
    except Exception as e:
        print('fail')
def button_a(xpath):
    button = browser.find_element_by_xpath(xpath)
    try:
        #点击搜索按钮
        button.click()
        print('成功搜索')
    except Exception as e:
        print('fail搜索')  
def clear_a(id_1):
    input_box = browser.find_element_by_xpath(id_1)
    try:
        input_box.clear()
        print('成功清空输入框')
    except Exception as e:
        print('fail清空输入框')
    #输出内容：成功清空输入框
    
input_a('username','中山市中智')
input_a('password','zsszz')
button = browser.find_element_by_id('notlogin')
try:
    #点击搜索按钮
    button.click()
    print('成功搜索')
except Exception as e:
    print('fail搜索')
#输出内容：成功搜索
button_a('//*[@id="menu"]/li[3]/a')
button_a('//*[@id="collapse-d87380ee375a4d38bb9c3ec974f7b000"]/div/ul/li[3]/a')
button = browser.find_element_by_xpath('//*[@id="menu"]/li[3]/a')
    
button_a('//*[@id="btnExport"]')   
input_b('//*[@id="beginTima"]','2020-04-01')  
element1=browser.find_element_by_xpath('//*[@id="jerichotab_5"]/div[1]/div[1]')
element11=element1.find_element_by_xpath('/html/body/ul/li/a')
element11=element1.find_element_by_xpath('//*[@id="beginTima"]')
element11.clear()
element11.send_keys("2020-04-01")
    
    
    
    
    
try:
    input_box.clear()
    print('成功清空输入框')
except Exception as e:
    print('fail清空输入框')
#输出内容：成功清空输入框
    
#定位输入框
input_box = browser.find_element_by_id('kw')
#输入关键词：selenium
input_box.send_keys('selenium')
#模拟回车操作
try:
    input_box.submit()
    print('成功回车')
except Exception as e:
    print('fail')
#输出内容：成功回车